/*
 * Copyright (c) 2007, TopCoder, Inc. All rights reserved.
 */

using System;

namespace TopCoder.Util.Calendar.Entry
{
    /// <summary>
    /// <para>
    /// This abstract class defines the basic and common properties for all calendar entries.
    /// </para>
    /// <para>
    /// A calendar entry will have an entryId, a type, a description and a date field.
    /// The using application may extend this class and add data fields specific to the application.
    /// </para>
    /// </summary>
    /// <remarks>
    /// Thread Safety: This class is not thread safe since it's highly mutable.
    /// </remarks>
    ///
    /// <author>snower, fuyun</author>
    /// <version>1.0</version>
    /// <copyright>Copyright (c) 2007, TopCoder, Inc. All rights reserved.</copyright>
    [Serializable]
    public abstract class BaseCalendarEntry
    {
        /// <summary>
        /// <para>
        /// Represents the id of this calendar entry.
        /// </para>
        /// <para>
        /// It can be accessed/modified via the namesake property. This is a must-set field,
        /// using application must make sure to set it. This field can be set to any non-negative integer.
        /// </para>
        /// </summary>
        private int entryId = -1;

        /// <summary>
        /// <para>
        /// Represents the date of this calendar entry.
        /// </para>
        /// <para>It's initialized to <c>DateTime.MinValue</c> and can be accessed/modified via the
        /// namesake property. This is a must-set field, using application must make sure to set it. It
        /// could be set to any meaningful date.
        /// </para>
        /// </summary>
        private DateTime date = DateTime.MinValue;

        /// <summary>
        /// <para>
        /// Represents the type of this calendar entry.
        /// </para>
        /// <para>
        /// It can be accessed/modified via the namesake property. This is a must-set field, using
        /// application must make sure to set it. It could be set to any type defined by the using
        /// application. It cannot be null once set.
        /// </para>
        /// </summary>
        private CalendarEntryType type = new CalendarEntryType(1, "Classes");

        /// <summary>
        /// <para>
        /// Represents the description of this calendar entry.
        /// </para>
        /// <para>
        /// It can be accessed/modified via the namesake property. This is a must-set field, using
        /// application must make sure to set it. It could be set to any meaningful string, it
        /// should not be null or empty once set.
        /// </para>
        /// </summary>
        private string description;

        /// <summary>
        /// Represents the property for the id of this calendar entry.
        /// </summary>
        /// <value>The id of this calendar entry.</value>
        /// <exception cref="ArgumentException">if value is negative when setting this property</exception>
        public virtual int EntryId
        {
            get
            {
                return entryId;
            }

            set
            {
//                if (value < 0)
//                {
//                    throw new ArgumentException(
//                        "The id of the calendar entry could not be set negative value.", "entryId");
//                }
                entryId = value;
            }
        }

        /// <summary>
        /// Represents the property for the date of this calendar entry.
        /// </summary>
        /// <value>
        /// The date of this calendar entry.
        /// </value>
        /// <exception cref="ArgumentException">
        /// if value is DateTime.MinValue when setting this property
        /// </exception>
        public virtual DateTime Date
        {
            get
            {
                return date;
            }

            set
            {
                if (value.Equals(DateTime.MinValue))
                {
                    throw new ArgumentException(
                        "The date of the calendar entry could not be set to DateTime.MinValue.", "date");
                }
                date = value;
            }
        }

        /// <summary>
        /// Represents the property for the type of this calendar entry.
        /// </summary>
        /// <value>The type of this calendar entry.</value>
        /// <exception cref="ArgumentNullException">if value is null when setting this property.</exception>
        public virtual CalendarEntryType Type
        {
            get
            {
                return type;
            }

            set
            {
//                if (value == null)
//                {
//                    throw new ArgumentNullException("type", "The type of the calendar entry could not be set null.");                    
//                }
                type = value;
            }
        }

        /// <summary>
        /// Represents the property for the description of this calendar entry.
        /// </summary>
        /// <value>The description of this calendar entry.</value>
        /// <exception cref="ArgumentNullException">if the value is null when setting this property.</exception>
        /// <exception cref="ArgumentException">if the value is empty when setting this property.</exception>
        public virtual string Description
        {
            get
            {
                return description;
            }

            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException(
                        "description", "The description of the calendar entry could not be set null.");
                }
                if (value.Trim().Length == 0)
                {
                    throw new ArgumentException(
                        "The description of this calendar entry could not be empty.", "description");
                }
                description = value;
            }
        }


        /// <summary>
        /// Creates a new BaseCalendarEntry instance. The construction is empty.
        /// </summary>
        protected BaseCalendarEntry()
        {
        }
    }
}